import cook from "./cook.js"
import customer from "./customer.js"
import message from "./entrance.js";

const data = {
    date:{ 
        week:1,
        day:1,
        foodNumer:0
    },
    
    money:500,
    renderMoney(change){
        let pay = document.querySelector(".money");
        data.money += change;
        pay.innerHTML = `￥${data.money}`
    },
    renderDate(data){
        let date = document.querySelector(".date");
        date.innerHTML = `W${data.week} D${data.day}`;
    },
    open:true,// open为true时顾客进店，临近一天结束时关门，顾客不进店。
    newDay(){
        console.log("新的一天开始了！");
        let thisDayMoney = 500;
        let thisWeekMoney = 0;
        setInterval(() => {
            setTimeout(() => {
                data.open = false;
            }, 200 * 1000);
            thisDayMoney = data.money - thisDayMoney;
            thisWeekMoney += thisDayMoney;
            
            if(data.date.day === 7){
                data.date.week++;
                data.date.day = 1;
                message.cleanRestaurant();
                data.renderDate(data.date)
                data.newWeek(thisWeekMoney);
            }else{
                data.date.day++;
                data.renderDate(data.date)
                message.cleanRestaurant();
                cook.foods = [];
                alert("做的好！你今天赚了" + thisDayMoney + "元，继续加油！")
            }
        }, 240 * 1000);
        customer.enterRestaurant();
    },
    newWeek(thisWeekMoney){
        let cooker = document.getElementsByClassName("cooker");
        let cookerNumber = 0;
        let cookerSalary = 0;
        for(let i = 0;i<cooker.length;i++){
            if(cooker[i].dataset.state !== "null"){
                cookerNumber++;
            }
        }
        cookerSalary = 0 - (cookerNumber * 150);
        data.renderMoney(cookerSalary);
        alert("这一周结束了，你一共赚了" + (thisWeekMoney + cookerSalary) + "元，其中支付给厨师的工作为" + cookerSalary + "元，继续加油！")
    },
}
export default data;